<?php 
namespace app\admin\controller;
use think\facade\Session;
use think\captcha\Captcha;
use think\Db;
/**
 * 
 */
class Index extends Base{
	
	public function index(){
		$this->assign('adminInfo',$this->adminInfo);
		return $this->fetch();
	}
	public function welcome(){
		$sysInfo['web'] = $_SERVER['SERVER_SOFTWARE'];
		$sysInfo['php_v'] = PHP_VERSION;
		$sysInfo['name'] = php_uname('s');
		$sysInfo['host'] = $_SERVER['HTTP_HOST'];
		$sysInfo['port'] = $_SERVER['SERVER_PORT'];

		$mysql_v = Db::query("SELECT VERSION()");
		$sysInfo['mysql_v'] = $mysql_v[0]['VERSION()'];
		$this->assign('sysInfo',$sysInfo);
		return $this->fetch();
	}
	public function login(){
		if($this->request->isPost() || $this->request->isAjax()){
			$captcha = new Captcha();
			$vertify = $this->request->param('vertify','','trim');
			if( !$captcha->check($vertify) ){
				$data= ['err'=>1,'content'=>'验证码错误！'];
				return $data;
			}
			$username = $this->request->param('username','','trim');
			$password = $this->request->param('password','','trim');

			$admin = db('administrator')->where('username = "'.$username.'" AND password = "'.encrypt($password).'"')->find();
			if( $admin ){
				Session::set('admin_id',$admin['id']);
				$data= ['err'=>0,'content'=>'登录成功！'];
				addAdminLog('后台登陆，操作成功');
				return $data;
			}else{
				// addAdminLog('后台登陆，操作失败');
				$data= ['err'=>1,'content'=>'用户名或密码错误！'];
				return $data;
			}
		}else{
			return $this->fetch();
		}
	}
	public function verify(){
	    $captcha = new Captcha();
        return $captcha->entry();    
    }
    public function logout(){
    	Session::delete('brscms');
    	$this->success("退出成功",url('index/login'));
    }
}